﻿using UnityEngine;
using System.Collections;

namespace BehaviorSystem
{
    /// <summary>
    /// 行为树
    /// </summary>
    public class BehaviourTree :BehaviourNode,IBehaviourTree
    {


        public IBehaviourNode RootNode { get; set; }


        public IBehaviourNode CurNode { get; private set; }


        public BehaviourTree(IBehaviorAgent agent):base(agent)
        {
            RootNode = this;
            CurNode = this;
            CurState = BTNodeState.Success;
            BehaviorSystemFacade.Inst.RegisterBehaviourAgent(agent);
        }

        public override BTNodeState ExcuteNode()
        {
            if (ChildrenNodes.Count>0)
            {
                CurState = ChildrenNodes[0].ExcuteNode();
                if (CurState == BTNodeState.Success || CurState == BTNodeState.Failure)
                {
                    ResetNode();
                }
            }
            return BTNodeState.Success;
        }

    }
}